/*
 * Copyright (c) 2011 Ball State University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.bsu.android.gtv.apps.bconnected.data;

import java.util.ArrayList;
import java.util.Calendar;

import edu.bsu.android.gtv.apps.bconnected.objects.Month;

/**
 * Data layer for the {@link Month} object
 * @author Kyle Parker, University Computing Services
 */
public class MonthData {
	private static ArrayList<Month> mMonths;

    /**
     * Loads an ArrayList<Month> with the months remaining in the current year and all months from the next year
     */
    public static void initializeMonth() {
    	mMonths = getMonthList();
    }
    
    /**
     * Returns the integer value of the {@link Month} object size
     * @return mMonths.size() | 0
     */
    public static int getMonthCount() {
        return mMonths.size();
    }

    /**
     * Returns a {@link Month} object at the index specified
     * @param i - the index of the object to be returned
     * @return mMonths.get(i)
     */
    public static Month getMonth(int i) {
        return mMonths.get(i);
    }

    /**
     * Returns the ArrayList<Month>
     * @return mMonths
     */
    public static ArrayList<Month> getMonths() {
        return mMonths;
    }

    /**
     * Returns the ArrayList<Month>
     * @return mMonths
     */
    private static ArrayList<Month> getMonthList() {
    	Calendar cal = Calendar.getInstance();
    	int month = cal.get(Calendar.MONTH) + 1;
    	int year = cal.get(Calendar.YEAR);
    	
        String[] monthName = {"January", "February",
            "March", "April", "May", "June", "July",
            "August", "September", "October", "November",
            "December"};
    	
		ArrayList<Month> months = new ArrayList<Month>();
		Month m;
		
		// Load the object with the months for the remainder of the year
		for (int i = month; i <= 12; i++){
			m = new Month();
			m.setMonthID(i);
			m.setYear(year);
			m.setMonthName(monthName[i-1]);
			m.setMonthWithYear(m.getMonthName() + " " + m.getYear());
			months.add(m);
		}
		
		// Load the object with the months for the following year
		for (int i = 1; i <= 12; i++){
			m = new Month();
			m.setMonthID(i);
			m.setYear(year + 1);
			m.setMonthName(monthName[i-1]);
			m.setMonthWithYear(m.getMonthName() + " " + m.getYear());
			months.add(m);
		}
		
		return months;
    }
}
